package chapter1.listSet.task;
/*
5：在List中放入若干整数，比如10个，然后删除其中的偶数。最后输出这个List
 */

import java.util.*;

public class Task5 {
    public static void main(String[] args) {
        Random random = new Random();
        Iterator<Integer> iterator;
       List<Integer> list=new ArrayList<>();
        int a;
        while (list.size() < 10) {
            list.add(random.nextInt());
        }
        System.out.println("List中的元素为：");
        for (Integer b : list)
            System.out.print(b + "  ");
        System.out.println();
        iterator = list.iterator();
        while (iterator.hasNext()) {
            if (((a = iterator.next()) % 2) == 0)
                iterator.remove();
        }
        System.out.println("删除偶数后，List中的元素为：");
        for (Integer b : list)
            System.out.print(b + "  ");
    }
}
